﻿/*
 * Module Name: BinaryTree.cs
 * 
 * Purpose: This is an implementation of a Binary Tree
 * 
 * Created by: Chris Tisdale
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common_Code.Heler_Functions;

namespace Common_Code.Math_Extensions
{
    class Filter
    {
        /*
         * Name: LowPassFilter
         * 
         * Parameters: double[] filterValue
         *             double RC (time constant)
         *             double dt (time interval)
         * 
         * Returns: Filtered Value
         * 
         * Purpose: To generate a low pass filter for input values
         */
        public double LowPassFilter(double[] filterValue, double RC, double dt)
        {
            var alpha = dt / (RC + dt);
            double y = 0;
            var prev = filterValue[0];
            for (var count = 1; count < filterValue.Length; count++)
            {
                y = alpha * filterValue[count] + (1 - alpha) * prev;
            }
            return y;
        }

        /*
         * Name: HightPassFilter
         * 
         * Parameters: double[] filterValue
         *             double RC (time constant)
         *             double dt (time interval)
         * 
         * Returns: Filtered Value
         * 
         * Purpose: To generate a high pass filter for input values
         */
        public double HightPassFilter(double[] filterValue, double RC, double dt)
        {
            var alpha = dt / (RC + dt);
            double y = 0;
            var prev = filterValue[0];
            for (var count = 1; count < filterValue.Length; count++)
            {
                y = alpha * prev + alpha * (filterValue[count] - filterValue[count - 1]);
            }
            return y;
        }

        /*
         * Name: BandPassFilter
         * 
         * Parameters: double[] filterValue
         *             double lowFrequency
         *             double highFrequency
         * 
         * Returns: Filtered Value
         * 
         * Purpose: To generate a band pass filter for input values
         */
        public double BandPassFilter(double[] filterValue, double lowFrequency, double highFrequency)
        {
            throw new NotImplementedException();
        }
    }
}
